package v2

import (
	rpcv1 "gluenet/internal/agent/api/rpc/v1"
	"gluenet/internal/agent/service/cprofilesvc"
	corev1 "gluenet/pkg/agent/types"
	"gluenet/pkg/agent/v2/rpc"
)

type CprofileGetter interface {
	Cprofile() GluenetCprofileInterface
}

type GluenetCprofileInterface interface {
	CprofileFlame(cprofileFlameReq *corev1.CprofileFlame) (result map[string]cprofilesvc.CprofileRootFunction, err error)
	CprofileFile(cprofileFileReq *corev1.CprofileFile) (result string, err error)
}

type gluenetCprofile struct {
	client rpc.Interface
}

func newGluenetCprofile(c *CoreClient) *gluenetCprofile {
	return &gluenetCprofile{
		client: c.RPCClient(),
	}
}

func (c *gluenetCprofile) CprofileFlame(cprofileFlameReq *corev1.CprofileFlame) (result map[string]cprofilesvc.CprofileRootFunction, err error) {
	err = c.client.Invoke().
		Api(rpcv1.CprofileFlame).
		Spec(*cprofileFlameReq).
		Do().
		Into(&result)
	return
}

func (c *gluenetCprofile) CprofileFile(cprofileFileReq *corev1.CprofileFile) (result string, err error) {
	err = c.client.Invoke().
		Api(rpcv1.CprofileFile).
		Spec(*cprofileFileReq).
		Do().
		Into(&result)
	return
}
